<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <button>promise(get)请求</button>
    <button>promise(post)请求</button>
    <p></p>

    <script src="./promist.js"></script>
    <script>

        let requestHead = 'http://localhost:8888';

        const oBtn = document.querySelectorAll('button');
        const oP = document.querySelector('p');

        oBtn[0].addEventListener('click', function () {
            promiseGetReult();
        })

        oBtn[1].addEventListener('click',function(){
            promisePostResult();
        })

        async function promiseGetReult() {
            const result = await promiseRequesrt(`${requestHead}/test/third`, 'get', 'name=张三&age=15');
            oP.innerHTML = result;
            console.log(JSON.parse(result));
        }

        async function promisePostResult(){
            const result = await promiseRequesrt(`${requestHead}/test/fourth`,'post','name=王五&age=22');
            oP.innerHTML = result;
            console.log(JSON.parse(result));
        }

    </script>
</body>

</html>